package com.xjggb.cloud.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.xjggb.cloud.entity.CommonResult;
import com.xjggb.cloud.entity.Payment;
import com.xjggb.cloud.myhandler.CustomerBlockHandler;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class RateLimitController {


    @GetMapping("/byResource")
    @SentinelResource(value = "byResource",blockHandler = "handleException")
    public CommonResult show(){
    return new CommonResult(200,"按资源限流ok",new Payment());
    }

    public CommonResult handleException(BlockException blockException){
        return new CommonResult(404,blockException.getClass().getCanonicalName()+"\t服务不可用");
    }




    @GetMapping("/rateLimit/customerBlockHandler")
    @SentinelResource(
            value = "customerBlockHandler",
            blockHandlerClass = CustomerBlockHandler.class,  //自定义全局兜底的类
            blockHandler = "handlerException1"    //兜底的方法
                )
    public CommonResult show3(){
        return new CommonResult(200,"客户自定义",new Payment(200L,"来了老弟"));
    }


}
